<template>
<div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
            <!-- 放置表单 -->
            <el-form ref="userForm" :model="userInfo" :rules="rules" label-width="120px" style="margin-left: 120px; margin-top:30px">
                <el-form-item label="账号:">
                <el-input v-model="userInfo.username" disabled style="width:300px" />
              </el-form-item>
                <el-form-item prop="nickname" label="昵称:">
                <el-input v-model="userInfo.nickname" style="width:300px" />
              </el-form-item>
              <el-form-item  prop="password" label="密码:">
                <el-input v-model="userInfo.password" style="width:300px" type="password" />
              </el-form-item>
              <!-- <el-form-item  prop="position" label="职位:">
                <el-input v-model="userInfo.position" style="width:300px"  />
              </el-form-item> -->
               <!-- <el-form-item prop="remarks"  label="备注:">
                <el-input v-model="userInfo.remarks" style="width:500px"  />
              </el-form-item> -->
              <el-form-item>
                <el-button type="primary" @click="saveUser">保存</el-button>
              </el-form-item>
            </el-form>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'
import {saveUserDetailById} from '@/api/user'
import { Session } from '@/utils/storage';

 export default {
  name: 'personal',
  data () {
   return {
userInfo: {
        //   专门存放基本信息
        nickname:'',//昵称
        username: '',
        password: '',
        id:''
      },
      rules: {
        password: [{ required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 16, message: '密码长度6-16位', trigger: 'blur' }],
        nickname:[{required: true, message: '昵称不能为空', trigger: 'blur'},
          { min: 2, max: 9, message: '密码长度6-16位', trigger: 'blur' }]
      }
   }
  },
  props:{},
  components: {
  },
  created () {
      this.userInfo =  this.userInfos.userInfos.item[0]
  },
  mounted () {
  }, 
  methods: {
       async saveUser() {
      try {
        // 校验
        await this.$refs.userForm.validate()
        await saveUserDetailById(this.userInfo.id,this.userInfo)
        const userInfos = Session.get('userInfo')
       if(userInfos){
            userInfos.item[0] = this.userInfo
            Session.set('userInfo', userInfos);
        }
        
        this.$message.success('保存成功')
      } catch (error) {
        console.log(error)
      }
    },
  }, 
  computed: {
      ...mapState(['userInfos'])
  },
  watch:{}
 }
</script>

<style scoped>

 
</style>
